package com.briup.srms.sms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.srms.sms.bean.ClazzRoom;
import com.briup.srms.sms.dao.ClazzRoomMapper;
import com.briup.srms.sms.dao.extend.ClazzRoomExtendMapper;
import com.briup.srms.sms.service.IClazzRoomService;
import com.jacky.base.utils.CustomerException;
import com.jacky.base.utils.PageVM;

@Service
public class ClazzRoomServiceImpl implements IClazzRoomService {
	
	@Autowired
	private ClazzRoomMapper clazzRoomMapper;
	@Autowired
	private ClazzRoomExtendMapper clazzRoomExtendMapper;
	
	@Override
	public PageVM<ClazzRoom> pageQuery(int page, int pageSize) {
		List<ClazzRoom> list = clazzRoomExtendMapper.query(page, pageSize);
		long total = clazzRoomExtendMapper.count();
		return new PageVM<>(page, pageSize, total, list);
	}
	@Override
	public void saveOrUpdate(ClazzRoom clazzRoom) {
		if(clazzRoom.getId() == null) {
			clazzRoomMapper.insert(clazzRoom);
		} else {
			clazzRoomMapper.updateByPrimaryKey(clazzRoom);
		}
		
	}
	@Override
	public void deleteById(long id) {
		// TODO Auto-generated method stub
		ClazzRoom dict = clazzRoomMapper.selectByPrimaryKey(id);
		if(dict == null) {
			throw new CustomerException("要删除的数据不存在");
		}
		clazzRoomMapper.deleteByPrimaryKey(id);
		
	}
}
